﻿using ByteSite.API.Model;
using ByteSite.Common;
using System;
using System.Net.Http;
using System.Text;
using System.Web;
using System.Web.Http;

namespace ByteSite.API.Controllers
{
    [RoutePrefix("api/auth2")]
    public class AuthController : ApiController
    {
        [HttpPost]
        [Route("access_token")]
        public HttpResponseMessage access_token()
        {
            HttpContextBase context = (HttpContextBase)Request.Properties["MS_HttpContext"];//获取传统context
            HttpRequestBase request = context.Request;//定义传统request对象

            AccessTokenRequest req = DTRequest.RequestFormParams<AccessTokenRequest>(request);
            LoggerHelper.Debug(JsonHelper2.ObjectToJSON(req));

            AccessTokenResponse resp = new AccessTokenResponse();
            resp.access_token = "qlycapi98bf71c8fc884b9264bbc7ed2";
            resp.expires_at = DateTime.Now.AddHours(12).ToString("yyyy-MM-dd HH:mm:ss");
            resp.success = true;

            LoggerHelper.Debug(JsonHelper2.ObjectToJSON(resp));
            var result = new HttpResponseMessage()
            {
                Content = new StringContent(JsonHelper2.ObjectToJSON(resp), Encoding.UTF8, "application/json")
            };
            return result;
        }
    }
}